# Contributor: George Hopkins <george-hopkins@null.net>
# Maintainer: George Hopkins <george-hopkins@null.net>
pkgname=kismet
_pkgver=2020-12-R3
pkgver=${_pkgver/-R/.}
pkgver=0.${pkgver/-/}
pkgrel=3
pkgdesc="Wireless network and device detector"
url="https://www.kismetwireless.net/"
arch="all"
license="GPL-2.0-only"
makedepends="linux-headers libnl3-dev libpcap-dev protobuf-dev protobuf-c-dev
	sqlite-dev zlib-dev"
subpackages="$pkgname-logtools
	$pkgname-linux-bluetooth:linux_bluetooth
	$pkgname-linux-wifi:linux_wifi
	$pkgname-nrf-51822:nrf_51822
	$pkgname-nxp-kw41z:nxp_kw41z
	"
options="!check" # no test-suite available
source="$pkgname-$pkgver.tar.xz::https://www.kismetwireless.net/code/kismet-$_pkgver.tar.xz
	sqlite3-longlong.patch
	"
builddir="$srcdir/kismet-$_pkgver"

[ "$CARCH" = "riscv64" ] && options="$options textrels"

prepare() {
	default_prepare
	update_config_sub
	sed -i "s/@VERSION@/$pkgver/" packaging/kismet.pc.in
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc/kismet \
		--disable-libusb \
		--disable-libwebsockets \
		--disable-python-tools
	make
}

package() {
	make DESTDIR="$pkgdir" install
	rm "$pkgdir"/usr/bin/kismet_discovery # example
}

logtools() {
	pkgdesc="$pkgdesc - log tools"

	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/kismetdb_* "$subpkgdir"/usr/bin
}

linux_bluetooth() {
	pkgdesc="$pkgdesc - Bluetooth capture support"
	depends="$pkgname"

	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/kismet_cap_linux_bluetooth "$subpkgdir"/usr/bin
}

linux_wifi() {
	pkgdesc="$pkgdesc - Wi-Fi capture support"
	depends="$pkgname"

	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/kismet_cap_linux_wifi "$subpkgdir"/usr/bin
}

nrf_51822() {
	pkgdesc="$pkgdesc - nRF51822 capture support"
	depends="$pkgname"

	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/kismet_cap_nrf_51822 "$subpkgdir"/usr/bin
}

nxp_kw41z() {
	pkgdesc="$pkgdesc - NXP KW41Z capture support"
	depends="$pkgname"

	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/kismet_cap_nxp_kw41z "$subpkgdir"/usr/bin
}

sha512sums="
6c4c95a9963977d5a383e34f662f814a803d0d36d7dbc35d3d0a42d3e67c20e8d46357df0ee544b8dd3c7f527bd43ef9c0d913577d4979f261764fc9761cd6d1  kismet-0.202012.3.tar.xz
1f49cf45963f32b1eaec9b15e5cab53f46999362f87daf9b39f8f244fa3dd1ac602f0a22eb04682a3a22abcaf2b09fc59060ff12626844e77125b6a28e4350bd  sqlite3-longlong.patch
"
